
import store from '../store'
import { getOrderInterval } from '../env'

let timerId

const start = () => {
  if (!timerId) {
    store.dispatch('order/getOrderList', {
      hasLoading: true
    })
  } else {
    clearInterval(timerId)
  }
  timerId = setInterval(() => {
    store.dispatch('order/getOrderList')
  }, getOrderInterval)
}

const stop = () => {
  if (timerId) {
    clearInterval(timerId)
    timerId = null
  }
}

const restart = () => {
  stop()
  start()
}

export default {
  start,
  stop,
  restart
}
